import java.nio.charset.Charset;

public class ValidIPAddress {

    public static String getIp(String ip){
        String ipv4="IPv4";
        String ipv6="IPv4";
        String neither="Neither";
        if(ip.indexOf(":")>-1){
            int index=-1;
            for (int i = 0; i < 8; i++) {
                int cur=(i==7?ip.length():ip.indexOf(":",index+1));
                if(cur<0){
                    return neither;
                }
                if(cur-index-1<1||cur-index-1>4){
                    return neither;
                }
                for (int j = index+1; j <cur ; j++) {
                    if(!Character.isDigit(ip.charAt(j))&&!('a'<=Character.toLowerCase(ip.charAt(j))&&Character.toLowerCase(ip.charAt(j))<='f')){
                        return neither;
                    }
                }
                index=cur;
            }
            return ipv6;

        }
        if(ip.indexOf(".")>-1){
            int index=-1;
            for (int i = 0; i < 4; i++) {
                int cur=(i==3?ip.length():ip.indexOf(".",index+1));
                if(cur-index-1<1||cur-index-1>3){
                    return neither;
                }
                int address=0;
                for (int j = index+1; j <cur ; j++) {
                    if(!Character.isDigit(ip.charAt(j))){
                        return neither;
                    }
                    address=address*10+(ip.charAt(j)-'0');
                }
                if(address>255){
                    return neither;
                }
                if (address > 0 && ip.charAt(index + 1) == '0') {
                    return "Neither";
                }

                if(address==0&&cur-index-1>1){
                    return neither;
                }
                index=cur;
            }
            return ipv4;
        }
        return neither;
    }

    public static void main(String[] args) {
        System.out.println(getIp("2001:0db8:85a3:0:0:8A2E:0370:7334"));
    }
}
